package overrideoverwrite;

/**
 * @ClassName FloatToLong
 * @Date 2024/11/28 11:47 38
 * @Author Jack Chen
 * @Description serenity-cucumber-auto-project-jack
 * @Version 1.0
 */

public class FloatToLong {
    public static void main(String[] args) {
        //method 1
        float decimalNumber = 203.54f;
        long roundedValue = Math.round(decimalNumber);
        System.out.println(decimalNumber);
        System.out.println("Round Value: "+roundedValue);

        //method 2  简单粗暴直接转换向下取整
        long truncatedValue = (long) decimalNumber;
        System.out.println("Truncated Value: "+truncatedValue);

        //method3 装箱
        Float x = Float.valueOf(decimalNumber); //先将float数值转换成Float对象
        long x1 = x.longValue();
        System.out.println("x1: " + x1);

//         会报错，因为包含小数点
//        long l = Long.parseLong(String.valueOf(decimalNumber));
//        System.out.println("long Value: " + l);

    }
}
